#!/bin/bash

#统计tcp协议的listen端口和established端口的个数

listen=0
es=0
while read line; do
if [ $(echo ${line} | awk '{print $6}') == LISTEN ];then
    let listen++

elif 
    [ $(echo ${line} | awk '{print $6}') == ESTABLISHED ];then
    let es++
 fi
done < <(netstat -antp | sed '1,2d')
    echo "$listen"
    echo "$es"
